#! /usr/bin/env python

import os
import sys
import shutil
import getopt

def install_audio(filepath):
	os.chdir("/etc/default/")
	if os.path.exists("pulseaudio"):
		if os.path.islink("pulseaudio"):
			os.remove("pulseaudio")
		else:
			shutil.move("pulseaudio","pulseaudio.cp")
	os.symlink(filepath,"pulseaudio")
	os.system("usermod -a -G pulse-access root")	

if __name__ == "__main__":
	path = ""
	opts,args = getopt.getopt(sys.argv[1:],"hf:",["help","file="])
	for o,a in opts:
		if o in ("-h","--help"):
			print "-h,--help: get the progame help"
			print "-f,--file: the pulseaudio file path,default is \"/opt/sys/settings/bin/sys/pulseaudio\""
			sys.exit()
		elif o in ("-f","--file"):
			path = a
	if path == "":
		path = "/opt/sys/settings/bin/sys/pulseaudio"
	install_audio(path)	
